package com.shanghaiyimu.yimiyangche.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.entity.City;

import java.util.List;

/**
 * Author:ShangHaiYiMu
 * Time:2017/7/31   10:36
 *
 */

public class CityAdapter extends BaseAdapter {
    private Context context;
    private List<City.ResultBean> datas;

    public CityAdapter(Context context, List<City.ResultBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas!=null?datas.size():0;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.view_select_city_list_item,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        City.ResultBean resultBean = datas.get(position);
        holder.cityName.setText(resultBean.getCityName());
        holder.cityName.setTag(resultBean.getCityID());
        return convertView;
    }
    static class ViewHolder{
        private TextView cityName;
        public ViewHolder(View view) {
            cityName = (TextView) view.findViewById(R.id.city_list_item);
        }
    }
}
